#pragma once

namespace fastbird
{

struct FB_CRITICAL_SECTION
{
	FB_CRITICAL_SECTION()
	{
		InitializeCriticalSection(&mCS);
	}

	~FB_CRITICAL_SECTION()
	{
		 DeleteCriticalSection(&mCS);
	}

	CRITICAL_SECTION mCS;
};

struct LOCK_CRITICAL_SECTION
{
	LOCK_CRITICAL_SECTION(const CRITICAL_SECTION* cs)
	{
		mCS = const_cast<LPCRITICAL_SECTION>(cs);
		EnterCriticalSection(mCS);
	}

	/*LOCK_CRITICAL_SECTION(FB_CRITICAL_SECTION* cs)
	{
		mCS = &(cs->mCS);
		EnterCriticalSection(mCS);
	}*/
	LOCK_CRITICAL_SECTION(FB_CRITICAL_SECTION& cs)
	{
		mCS = &(cs.mCS);
		EnterCriticalSection(mCS);
	}
	~LOCK_CRITICAL_SECTION()
	{
		LeaveCriticalSection(mCS);
	}

	LPCRITICAL_SECTION mCS;
};

inline void EnterCriticalSection(FB_CRITICAL_SECTION& cs)
{
	EnterCriticalSection((LPCRITICAL_SECTION)&cs);
}

inline void LeaveCriticalSection(FB_CRITICAL_SECTION& cs)
{
	LeaveCriticalSection((LPCRITICAL_SECTION)&cs);
}


}